package org.itboys.seller.service;

import org.itboys.seller.constant.CaliforniaSiteConstant;
import org.itboys.seller.mapper.MatchInfoMapper;
import org.itboys.seller.meta.MatchInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author hzliangchong1@corp.netease.com
 *         Date 2016/10/30.
 */
@Service
public class MatchInfoDao {

    private static final Logger logger = LoggerFactory.getLogger(MatchInfoDao.class);

    @Resource
    private MatchInfoMapper matchInfoMapper;
    @Resource
    private WalletService walletService;
    @Resource
    private CaliforniaSiteUserService californiaSiteUserService;

    @Transactional
    public void updateMatchInfo(MatchInfo info, boolean freeze) {
        matchInfoMapper.updateByPrimaryKey(info);
        if (freeze) {
            walletService.addMoney(info.getProviderAcc(), CaliforniaSiteConstant.WalletType.TYPE_BENXI,
                    info.getAmount() + info.getProfit());
            californiaSiteUserService.freeAccount(info.getProviderAcc());
            logger.info("account {} was freezed by put in benxi wallet time out.", info.getProviderAcc());
        }
    }
}
